﻿<UserControl x:Class="MediaAssistant.Controls.MovieDetail.MovieDetailView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:Converters="clr-namespace:MediaAssistant.Converters" mc:Ignorable="d" 
             d:DesignHeight="240" d:DesignWidth="600" Background="{StaticResource BodyBackground}">
    <UserControl.Resources>
        <Converters:DoneStatusVisibilityConverter x:Key="DoneStatusVisibilityConverter" />
      <Style x:Key="LibraryItemsControlStyle" TargetType="{x:Type ItemsControl}" >
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Button Content="{Binding Title}" Style="{StaticResource LinkButtonStyle}" Margin="5,0,5,0" 
                                ToolTip="{Binding Converter={StaticResource LibraryItemSearchTooltipConverter}}"
                                Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}},Path=DataContext.DataSource.SelectLibraryItemCommand}"
                                CommandParameter="{Binding}"/>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <WrapPanel Orientation="Horizontal"/>
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Converters:NullVisibilityConverter x:Key="NullVisibilityConverter" />
        <Converters:RecommendedMovieCountConverter x:Key="RecommendedMovieCountConverter" />
        <Converters:RatedTooltipConverter x:Key="RatedTooltipConverter" />
    </UserControl.Resources>
    <Grid>
        <DockPanel>
            <StackPanel DockPanel.Dock="Top" Margin="5">
                <StackPanel.Visibility>
                    <MultiBinding Converter="{StaticResource DoneStatusVisibilityConverter}">
                        <Binding Path="DataSource.SelectedMovie"/>
                        <Binding Path="DataSource.SelectedMovie.Status"/>
                        <Binding Path="DataSource"/>
                    </MultiBinding>
                </StackPanel.Visibility>
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                    <TextBlock Text="{Binding DataSource.SelectedMovie.Title}" ToolTip="{Binding DataSource.SelectedMovie.Title}" FontSize="18" FontWeight="Bold" Margin="0,5" MaxWidth="230" TextTrimming="CharacterEllipsis"/>
                    <TextBlock Text="-(" FontSize="18" Margin="5,5,0,5"/>
                    <Button Content="{Binding DataSource.SelectedMovie.Year}" 
                                ToolTip="{Binding DataSource.SelectedMovie.Year, Converter={StaticResource LibraryItemSearchTooltipConverter}}"
                                FontSize="18" Margin="0,5" Style="{StaticResource LinkButtonStyle}" 
                                Command="{Binding SelectYearCommand}"/>
                    
                    <TextBlock Text=")" FontSize="18" Margin="0,5"/>

                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <Button Content="{Binding DataSource.SelectedMovie.Rated}" 
                                Style="{StaticResource LinkButtonStyle}"  
                                Margin="0,5" FontWeight="Bold"
                                Command="{Binding SelectRatedLibraryItemCommand}"
                                ToolTip="{Binding DataSource.SelectedMovie.Rated, Converter={StaticResource RatedTooltipConverter}}"
                                />
                    <TextBlock Text="{Binding DataSource.SelectedMovie.Runtime}" Margin="10,5" Foreground="Gray"/>
                    <ItemsControl ItemsSource="{Binding DataSource.SelectedMovie.Genres}" Style="{StaticResource LibraryItemsControlStyle}" Margin="0,5,0,5"/>
                </StackPanel>
            </StackPanel>
            <Grid DockPanel.Dock="Bottom">
                <StackPanel DockPanel.Dock="Left" Margin="5">
                    <StackPanel.Visibility>
                        <MultiBinding Converter="{StaticResource DoneStatusVisibilityConverter}">
                            <Binding Path="DataSource.SelectedMovie"/>
                            <Binding Path="DataSource.SelectedMovie.Status"/>
                            <Binding Path="DataSource"/>
                        </MultiBinding>
                    </StackPanel.Visibility>
                    <Border Margin="0,5" BorderThickness="1" BorderBrush="LightGray"/>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding DataSource.SelectedMovie.Rating, StringFormat='Rating: {0}/10'}" FontSize="15" VerticalAlignment="Center"/>
                        <TextBlock Text="{Binding DataSource.SelectedMovie.Votes, StringFormat='Votes: {0}'}" Margin="20,0"  FontSize="15" VerticalAlignment="Center"/>
                        <Button 
                            Content="{Binding DataSource.RecommendedMovieCount, Converter={StaticResource RecommendedMovieCountConverter}}" 
                            Style="{StaticResource LinkButtonStyle}" 
                            Command="{Binding ShowRecommendedMoviesCommand}"
                            HorizontalAlignment="Right" Margin="10,5,0,0"  FontSize="15"/>
                    </StackPanel>
                    <Border Margin="0,5" BorderThickness="1" BorderBrush="LightGray"/>
                    <TextBlock Text="{Binding DataSource.SelectedMovie.Plot}" TextWrapping="Wrap"/>
                    <StackPanel Orientation="Horizontal" Margin="0,5">
                        <TextBlock Text="Director:" Margin="0,0,5,0"/>
                        <ItemsControl ItemsSource="{Binding DataSource.SelectedMovie.Directors}" Style="{StaticResource LibraryItemsControlStyle}"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Writers:" Margin="0,0,5,0"/>
                        <ItemsControl ItemsSource="{Binding DataSource.SelectedMovie.Writers}" Style="{StaticResource LibraryItemsControlStyle}"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" Margin="0,5">
                        <TextBlock Text="Stars:" Margin="0,0,5,0"/>
                        <ItemsControl ItemsSource="{Binding DataSource.SelectedMovie.Stars}" Style="{StaticResource LibraryItemsControlStyle}"/>
                    </StackPanel>
                </StackPanel>
            </Grid>
            <Border BorderBrush="LightGray" BorderThickness="2" DockPanel.Dock="Top" Padding="2" Margin="2">
                <Border.Visibility>
                    <MultiBinding Converter="{StaticResource DoneStatusVisibilityConverter}">
                        <Binding Path="DataSource.SelectedMovie"/>
                        <Binding Path="DataSource.SelectedMovie.Status"/>
                        <Binding Path="DataSource"/>
                    </MultiBinding>
                </Border.Visibility>
                <Grid>
                    <ContentControl Content="{StaticResource MoviePosterImage}"
                                    Visibility="{Binding DataSource.SelectedMovie.PosterImage, Converter={StaticResource NullVisibilityConverter}}"/>
                    <Image HorizontalAlignment="Center" VerticalAlignment="Center">
                        <Image.Source>
                            <MultiBinding Converter="{StaticResource PosterImageConverter}">
                                <Binding Path="DataSource.SelectedMovie"/>
                                <Binding Path="DataSource.SelectedMovie.Poster"/>
                                <Binding Path="DataSource.SelectedMovie.PosterImage"/>
                            </MultiBinding>
                        </Image.Source>
                    </Image>
                </Grid>
            </Border>
        </DockPanel>
    </Grid>
</UserControl>
